'

'Imports OpenArchive.Components
Imports OpenArchive.Document.Components
Imports OpenArchive.Collections

Namespace OpenArchive
    Namespace Document
        ''' <summary>
        ''' 
        ''' </summary>
        ''' <remarks></remarks>
        <Reflection.DefaultMember("Item")> _
  Public MustInherit Class Document
            Implements Global.System.Collections.ICollection
            'Friend m_id As Long
            Private m_ArchiveProperties As ArchiveProperties
            Friend m_componentlist As ComponentList
            Protected Sub New()
                m_componentlist = New ComponentList(Me)
                Init()
            End Sub
            Protected Sub Init()
                m_ArchiveProperties = New ArchiveProperties()
                Dim _infocomp As New InfoComponent()
                _infocomp.DocType = Me.GetType.Name
                m_componentlist.Add(_infocomp)
            End Sub
            Default Public Overloads ReadOnly Property Item(ByVal Name As String) As IComponent
                Get
                    For Each _component As Component In m_componentlist.Values
                        If _component.GetType.Name = Name Then
                            Return _component
                        End If
                    Next
                    Return Nothing
                End Get
            End Property
            Default Public Overloads ReadOnly Property Item(ByVal Instance As Integer, ByVal Name As String) As IComponent
                Get
                    Return m_componentlist.Item(Instance.ToString("D2") & "." & Name)
                End Get
            End Property
            Public ReadOnly Property Components() As List(Of Components.IComponent)
                Get
                    Return m_componentlist.Values.ToList
                End Get
            End Property
            Public ReadOnly Property UUID() As Guid
                Get
                    Return Infocomponent.Guid
                End Get
            End Property
            Public ReadOnly Property ID() As Long
                Get
                    Return ArchiveProperties.ID
                End Get
            End Property
            Public Property Parent() As Folder
                Get
                    'Return ArchiveProperties.Archive.Documents.Dokument(_Infocomponent.ParentID)
                End Get
                Set(ByVal value As Folder)
                    'If IsReadOnly Then _
                    '   Throw New NotSupportedException
                    'Infocomponent.ParentID = value.ID
                End Set
            End Property
            Public Property ArchiveProperties() As ArchiveProperties
                Get
                    Return m_ArchiveProperties
                End Get
                Friend Set(ByVal value As ArchiveProperties)
                    m_ArchiveProperties = value
                End Set
            End Property

            'Private ReadOnly Property _Indexcomponent() As List(Of IndexComponent)
            '	Get
            '		Dim indexlist As List(Of IndexComponent) = New List(Of IndexComponent)
            '		For Each component As Component In m_componentlist
            '			If TypeOf component Is IndexComponent Then
            '				indexlist.Add(DirectCast(component, IndexComponent))
            '			End If
            '		Next
            '		Return indexlist
            '	End Get
            'End Property
            'Public ReadOnly Property Archive() As Archive
            '    Get
            '        Return m_Archive
            '    End Get
            'End Property
            Private ReadOnly Property Infocomponent() As InfoComponent
                Get
                    Return m_componentlist.Item(0.ToString("D2") & "." & GetType(InfoComponent).Name)
                End Get
            End Property
            ''' <summary>
            ''' 
            ''' </summary>
            ''' <value></value>
            ''' <returns></returns>
            ''' <remarks></remarks>
            Public ReadOnly Property Indices() As Indices
                Get
                    Dim _indeces As New Indices()

                    For Each _component As Component In m_componentlist.Values
                        If TypeOf _component Is IndexComponent Then
                            _indeces.Add(_component)
                        End If
                    Next
                    Return _indeces
                End Get
            End Property
            Friend Overloads Sub Add(ByVal item As Components.Component)
                m_componentlist.Add(item)
            End Sub
            Friend Overloads Sub Add(ByVal instance As Integer, ByVal item As Components.IComponent)
                m_componentlist.Add(instance, item)
            End Sub
            Friend Overloads Function Contains(ByVal item As Components.IComponent) As Boolean
                Return m_componentlist.Values.Contains(item)
            End Function
            Public Overloads Function Contains(ByVal Instance As Integer, ByVal item As Components.IComponent) As Boolean
                Return m_componentlist.Keys.Contains(Instance.ToString("D2") & "." & item.GetType().Name)
            End Function
            ''' <summary>
            ''' Returns the number of components
            ''' </summary>
            ''' <value></value>
            ''' <returns>Returns the number of components</returns>
            ''' <remarks></remarks>
            Public ReadOnly Property Count() As Integer Implements Global.System.Collections.ICollection.Count
                Get
                    Return m_componentlist.Count
                End Get
            End Property

            Friend Function Remove(ByVal item As Components.IComponent) As Boolean
                'Return m_componentlist.Remove(item)
            End Function

            Public Sub CopyTo(ByVal array As Global.System.Array, ByVal index As Integer) Implements Global.System.Collections.ICollection.CopyTo

            End Sub

            Public ReadOnly Property IsSynchronized() As Boolean Implements Global.System.Collections.ICollection.IsSynchronized
                Get
                    Return True
                End Get
            End Property

            Public ReadOnly Property SyncRoot() As Object Implements Global.System.Collections.ICollection.SyncRoot
                Get
                    Return Me
                End Get
            End Property

            Public Function GetEnumerator() As Global.System.Collections.IEnumerator Implements Global.System.Collections.IEnumerable.GetEnumerator
                Return New DocComponentEnumerator(m_componentlist)
            End Function
        End Class

    End Namespace
End Namespace



